<template>
  <el-form-item
    :label="props.info.cn"
    size="mini"
  >
    <span>{{ props.data||props.info.info }}</span>
    <el-button size="mini" type="info" @click="read">查看</el-button>
    <el-button v-if="showUpload" size="mini" type="primary">
      <el-upload
        :action="props.info.url"
        :show-file-list="false"
        :on-change="myUpload"
        :on-success="handleSuccess"
        :on-error="onError"
      >
        上传
      </el-upload>
    </el-button>
    <el-button v-if="showDel" size="mini" type="danger" @click="del">删除</el-button>
  </el-form-item>
</template>

<script>
export default {
  name: 'UploadPdf',
  props: {
    props: {
      type: Object
    },
    showUpload: {
      type: Boolean,
      default: false
    },
    showDel: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    myUpload(file) {
      this.$emit('myUpload', file, this.props)
    },
    handleSuccess(res, file) {
      this.$emit('handleSuccess', res, file, this.props)
    },
    read() {
      this.$emit('read', this.props)
    },
    del() {
      this.$emit('del', this.props)
    },
    onError() {
      this.$alert('上传失败', '提示', {
        confirmButtonText: '确定'
      })
    }
  }
}
</script>

<style scoped>
    span + .el-button {
        margin-left: 10px;
    }
</style>
